package com.eckey.lab.controller;

import com.alibaba.fastjson.JSON;
import com.eckey.lab.constant.ResultBean;
import com.eckey.lab.entity.Page;
import com.eckey.lab.entity.bo.HotelBo;
import com.eckey.lab.entity.bo.QueryParams;
import com.eckey.lab.service.IHotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: Marinc
 * @CreateTime: 2023-07-06  10:39
 * @Description: 酒店测试控制器
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/hotel")
public class HotelController {

    @Autowired
    private IHotelService hotelService;

    @GetMapping("/exits")
    public ResultBean testExits() {
        boolean flag = hotelService.queryExitsHotel();
        return ResultBean.success(flag);
    }

    @GetMapping("/list")
    public ResultBean queryByParams(QueryParams queryParams) {
        log.info("查询列表，入参：{}", JSON.toJSONString(queryParams));
        Page page = hotelService.queryListByParams(queryParams);
        return ResultBean.success(page);
    }

    @GetMapping("/countByCity")
    public ResultBean countListByCity() {
        List<HotelBo> hotelBos = hotelService.countListByCity();
        return ResultBean.success(hotelBos);
    }

    @GetMapping("/countByBrand")
    public ResultBean countByBrand() {
        Map<String, List<String>> stringListMap = hotelService.countByBrand();
        return ResultBean.success(stringListMap);
    }

    //根据条件返回聚合对象
    @GetMapping("/countByParams")
    public ResultBean countByParams(QueryParams queryParams) {
        Page page = hotelService.countByParams(queryParams);
        return ResultBean.success(page);
    }

    //自动补全搜索，根据输入拼音
    @GetMapping("/search")
    public ResultBean search(String pinyin) {
        List<String> list = hotelService.searchByPinyin(pinyin);
        return ResultBean.success(list);
    }

    @GetMapping("/test")
    public ResultBean test() {
        return ResultBean.success("请求sentinel成功");
    }

    @GetMapping("/update")
    public ResultBean update() {
        return ResultBean.success("更新sentinel成功");
    }
}
